"""
Copyright 2012 Wieser Dietmar, Margit Mutschlechner.

This file is part of Multimedia Social Networking Platform.

Multimedia Social Networking Platform is free software: 
you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Multimedia Social Networking Platform is distributed
in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Multimedia Social Networking Platform.  
If not, see <http://www.gnu.org/licenses/>.

"""

from msnp.service import utils
from msnp.persistence import XMLController

class RescanStatus():
    """Class containing the two synch status types. This is one of "START_SYNCH", "SYNCH_DONE"."""
    START_SYNCH = "START_SYNCH"
    SYNCH_DONE = "SYNCH_DONE"

class Player():
    """This class contains the information about a specific player.
    
    Parameters:
        __playerName: A String containing the player's name.
        __pNameLinux: A String containing the command for starting the player on Linux.
        __pNameWindows: A String containing the command for starting the player on Windows.
    """
    def __init__(self, playerName, pNameLinux, pNameWindows):
        """The init method."""
        if playerName != None:
            playerName = unicode(playerName)
        if pNameLinux != None:
            pNameLinux = unicode(pNameLinux)
        if pNameWindows != None:
            pNameWindows = unicode(pNameWindows)
        self.__playerName = playerName
        self.__pNameLinux = pNameLinux
        self.__pNameWindows = pNameWindows
        
    def getName(self):
        """Returns the parameter __playerName."""
        return self.__playerName
    
    def getPNameLinux(self):
        """Returns the parameter __pNameLinux."""
        return self.__pNameLinux
    
    def getPNameWindows(self):
        """Returns the parameter __pNameWindows."""
        return self.__pNameWindows
    
    @classmethod
    def AMAROK(cls):
        """Class method to create a Player object for the player Amarok.
        
        Returns:
            A Player object is returned, where all parameters are set for the Amarok player.
        """
        return Player("AMAROK", "amarok", "amarok.exe")
    
class SynchChangeEvent():
    """Class containing the two synch change event types. This is one of "INSERT", "UPDATE"."""
    INSERT = 'INSERT'
    UPDATE = 'UPDATE'
    
class MediaType():
    """Class containing the two media types. This is one of "AUDIO", "VIDEO"."""
    AUDIO = 'AUDIO'
    VIDEO = 'VIDEO'
    
class NetSynchChangeSource():
    """Class containing the three media change sources. This is one of "PLAYER", "NETWORK", "INITIAL"."""
    PLAYER = 'PLAYER'
    NETWORK = 'NETWORK'
    INITIAL = 'INITIAL'

class ReturnType:
    """Class containing the three return types when altering the media database. This is one of "ERROR", "UPDATED", "NOT_UPDATED"."""
    ERROR = -1
    UPDATED = 0
    NOT_UPDATED = 1

###################
## SYNCH_CHANGES ##
###################

class SynchChanges():
    """This class contains the information about a change in the player database. It represents one entry of the synch_changes table in the media database.
    
    Parameters:
        __id: An integer value containing the id of the entry in the snych_changes table that is represented by this SynchChanges object.
        __tablename: A String containing the table name where the change happened.
        __sortorder:
        __rowId: An integer value representing the row in which the change happened.
        __columnname: A String containing the column name where the change happened.
        __player: A String representing the player in which database the change happened.
        __event: A String representing the type of event.
        __old: A String containing the old value of the column or None if the change was an insertion.
        __new: A String containing the new value of the column.
        __changeTime: A float representing the time when the change happened.
    """
    def __init__(self, id, tablename, sortorder, rowId, columnname, player, event, old, new, changeTime):
        """The init method."""
        self.__id = id
        self.__tablename = tablename
        self.__sortorder = sortorder
        self.__rowId = rowId
        self.__columnname = columnname
        self.__player = player
        self.__event = event
        if old != None:
            old = unicode(old)
        if new != None:
            new = unicode(new)
        self.__old = old
        self.__new = new
        self.__changeTime = changeTime
        
    def getId(self):
        """Returns the parameter __id."""
        return self.__id
    
    def getTablename(self):
        """Returns the parameter __tablename."""
        return self.__tablename
    
    def getSortorder(self):
        """Returns the parameter __sortorder."""
        return self.__sortorder
    
    def getRowId(self):
        """Returns the parameter __rowId."""
        return self.__rowId
    
    def getColumnname(self):
        """Returns the parameter __columnname."""
        return self.__columnname
    
    def getPlayer(self):
        """Returns the parameter __player."""
        return self.__player
    
    def getEvent(self):
        """Returns the parameter __event."""
        return self.__event
    
    def getOld(self):
        """Returns the parameter __old."""
        return self.__old
    
    def getNew(self):
        """Returns the parameter __new."""
        return self.__new
    
    def getChangeTime(self):
        """Returns the parameter __changeTime."""
        return self.__changeTime
    
    def isConnected(self, change):
        """Checks whether two changes are connected.
        
        Compares the row id, the event type and the table name of the current SynchChanges object and the given one.
        
        Args:
            change: A SynchChanges object that has to be compared with the current one.
            
        Returns:
            True is returned if the two changes are connected, i.e. if their row id, event type and table name are the same.
        """
        if self.__rowId == change.getRowId() and self.__event == change.getEvent() and self.__tablename == change.getTablename():
            return True;
        return False;
    
#######################
## NET_SYNCH_CHANGES ##
#######################

class NetSynchChanges():
    """This class contains the information about a change in the media databaseh. It represents one entry of the net_synch_changes table in the media database.
    
    Parameters:
        __id: An integer value containing the id of the entry in the snych_changes table that is represented by this SynchChanges object.
        __media_id: An integer value containing the id of the corresponding media id.
        __groupname: A String containing the group name from where the change originates.
        __ownername: A String containing the owner name from where the change originates.
        __username: A String containing the user name from where the change originates.
        __timestamp: A float value containing the exact time when the changes happened.
        __processed: A boolean value set to True if the change was processed, False otherwise.
        __source: A String containing the source of the change, either "INITIAL", "PLAYER" or "NETWORK".
        __relevent: A boolean value whether the change is still relevant (application was not restarted since the change). Default True.
    """
    def __init__(self, media_id, groupname, ownername, username, timestamp, processed, source, relevant=True, id=None):
        """The init method."""
        self.__id = id
        self.__media_id = media_id
        if groupname != None:
            groupname = unicode(groupname)
        if ownername != None:
            ownername = unicode(ownername)
        self.__groupname = groupname
        self.__ownername = ownername
        self.__username = username
        if timestamp == None:
            self.__timestamp = utils.DateFormatter.formatTimeAsFloat()
        else:
            self.__timestamp = timestamp
        self.__processed = processed
        self.__source = source
        self.__relevant = relevant
        
    def setMediaId(self, media_id):
        """Sets the parameter __media_id to the given one."""
        self.__media_id = media_id
        
    def getId(self):
        """Returns the parameter __id."""
        return self.__id
    
    def getMediaId(self):
        """Returns the parameter __media_id."""
        return self.__media_id
    
    def getGroupname(self):
        """Returns the parameter __groupname."""
        return self.__groupname
    
    def getOwnername(self):
        """Returns the parameter __ownername."""
        return self.__ownername
    
    def getUsername(self):
        """Returns the parameter __username."""
        return self.__username
    
    def getTimestamp(self):
        """Returns the parameter __timestamp."""
        return self.__timestamp
    
    def isProcessed(self):
        """Returns the parameter __processed."""
        return self.__processed
    
    def getSource(self):
        """Returns the parameter __source."""
        return self.__source
    
    def isRelevant(self):
        """Returns the parameter __relevant."""
        return self.__relevant
     

class SynchContent():
    """This class contains synchronization content to be sent to another user.
    
    Parameters:
        __audioList: A list of Audio objects containing the audios to be sent to the other user.
        __groupname: A String containing the group name for which the content was retrieved and sent.
        __ownername: A String containing the owner name.
        __username: A String containing the user name to which the content is sent.
        __sendernaame: A String conatining the sender's name which sent the content.
    """
    def __init__(self, audioList, groupname, ownername, senderName):
        """The init method."""
        self.__audioList = audioList
        if groupname != None:
            groupname = unicode(groupname)
        if ownername != None:
            ownername = unicode(ownername)
        if senderName != None:
            senderName = unicode(senderName)
        self.__groupname = groupname
        self.__ownername = ownername
        self.__senderName = senderName
        
    def getAudioList(self):
        """Returns the parameter __audioList."""
        return self.__audioList
    
    def getGroupname(self):
        """Returns the parameter __groupname."""
        return self.__groupname
    
    def getOwnername(self):
        """Returns the parameter __ownername."""
        return self.__ownername
    
    def getSenderName(self):
        """Returns the parameter __senderName."""
        return self.__senderName


class MediaReceiverQueueEntry():
    """An instance of this class represents one entry of the media receiving queue,
    which stores for every user the groups because of which it receives synchronization content.
    
    Parameters:
        __group: A list of Group objects containing the groups for which the user should receive synchronization content.
        __timestamp: A float value containing the exact time when the entry was created.
    """
    def __init__(self, group, timestamp):
        """The init method."""
        self.__group = group
        self.__timestamp = timestamp
    
    def getTimestamp(self):
        """Returns the parameter __timestamp."""
        return self.__timestamp
    
    def getGroup(self):
        """Returns the parameter __group."""
        return self.__group

################
## MEDIA_DATA ##
################

class Media():
    """An instance of this class represents an entry of the media table in the media database.
    
    Parameters:
        __id: An integer value containing the id of the entry.
        __mediaType: A String representing the type of the entry, either AUDIO or VIDEO.
        __title: A String containing the name of the Media object.
        __year: A Integer containing the year when the Media object was created.
        __composer: A String containing the name of the composer.
        __collection: A Collection object representing the collection of the entry.
        __genre: A Genre object representing the genre of the entry.
        __length: An integer value containing the length of the media.
        __filesize: An integer value containing the size of the file where the media is stored.
        __ratings: A list of Rating objects belonging to this entry.
    """
    def __init__(self, id, mediaType, title, year, composer, collection, genre, length, filesize, ratings):
        """The init method."""
        self.__id = id
        self.__mediaType = mediaType
        if title != None:
            title = unicode(title)
        if composer != None:
            composer = unicode(composer)
        self.__title = title
        self.__year = year
        self.__composer = composer
        #instance of class collection
        self.__collection = collection
        #instance of class genre
        self.__genre = genre
        self.__length = length
        self.__filesize = filesize
        #list of instances of class rating
        self.__ratings = ratings
        
    def getId(self):
        """Returns the parameter __id."""
        return self.__id
    
    def setId(self, id):
        """Sets the parameter __id to the given one."""
        self.__id = id
    
    def getMediaType(self):
        """Returns the parameter __timestamp."""
        return self.__mediaType
    
    def getTitle(self):
        """Returns the parameter __title."""
        return self.__title
    
    def getYear(self):
        """Returns the parameter __year."""
        return self.__year
    
    def getComposer(self):
        """Returns the parameter __composer."""
        return self.__composer
    
    def getCollection(self):
        """Returns the parameter __collection."""
        return self.__collection
    
    def setCollection(self, collection):
        """Sets the parameter __collection."""
        self.__collection = collection
    
    def getGenre(self):
        """Returns the parameter __genre."""
        return self.__genre
    
    def setGenre(self, genre):
        """Sets the parameter __genre."""
        self.__genre = genre
    
    def getLength(self):
        """Returns the parameter __length."""
        return self.__length
    
    def getFilesize(self):
        """Returns the parameter __filesize."""
        return self.__filesize
    
    def getRatings(self):
        """Returns the parameter __ratings."""
        return self.__ratings
    
    def setRatings(self, ratings):
        """Returns the parameter __ratings."""
        self.__ratings = ratings
        
    def getRatingForUsername(self, username):
        """Returns the parameter __rating for a certain username or None if no such rating exists.
        
        Args:
            username: The user name for which the rating should be retrieved.
        """
        if self.__ratings != None and len(self.__ratings) > 0:
            for rating in self.__ratings:
                if rating.getUsername() == username:
                    return rating
        return None
    
    @classmethod
    def createMedia(cls, title, year, composer, collection, genre, length, filesize, ratings, mediaType=MediaType.AUDIO, id=None):
        """Class method to create a Media object with the given parameters.
        
        Args:
            title: A String containing the name of the Media object.
            year: A Integer containing the year when the Media object was created.
            composer: A String containing the name of the composer.
            collection: A Collection object representing the collection of the entry.
            genre: A Genre object representing the genre of the entry.
            length: An integer value containing the length of the media.
            filesize: An integer value containing the size of the file where the media is stored.
            ratings: A list of Rating objects belonging to this entry.
            mediaType: A String representing the type of the entry, either AUDIO or VIDEO. Default MediaType.AUDIO.
            id: An integer value containing the id of the entry. Default None.
        
        Returns:
            A Media object is returned, where all parameters are set to the given ones.
        """
        m = Media(id, mediaType, title, year, composer, collection, genre, length, filesize, ratings)
        return m
        
class Genre():
    """An instance of this class represents an entry of the genre table in the media database.
    
    Parameters:
        __id: An integer value containing the id of the entry.
        __name: A String representing the name of the genre.
    """
    def __init__(self, id, name):
        """The init method."""
        self.__id = id
        if name != None:
            name = unicode(name)
        self.__name = name
        
    def getId(self):
        """Returns the parameter __id."""
        return self.__id
    
    def setId(self, id):
        """Sets the parameter __id."""
        self.__id = id
    
    def getName(self):
        """Returns the parameter __name."""
        return self.__name
    
    @classmethod
    def createGenre(cls, name, id=None):
        """Class method to create a Genre object with the given parameters.
        
        Args:
            name: A String representing the name of the genre.
            id: An integer value containing the id of the entry. Default None.
            
        Returns:
            A Genre object is returned, where all parameters are set to the given ones.
        """
        if name == None:
            return None
        g = Genre(id, name)
        return g
    
class Collection():
    """An instance of this class represents an entry of the collections table in the media database.
    
    Parameters:
        __id: An integer value containing the id of the entry.
        __name: A String representing the name of the collection.
    """
    def __init__(self, id, name):
        """The init method."""
        self.__id = id
        if name != None:
            name = unicode(name)
        self.__name = name
        
    def getId(self):
        """Returns the parameter __id."""
        return self.__id
    
    def setId(self, id):
        """Sets the parameter __id."""
        self.__id = id
    
    def getName(self):
        """Returns the parameter __name."""
        return self.__name
    
    @classmethod
    def createCollection(cls, name, id=None):
        """Class method to create a Collection object with the given parameters.
        
        Args:
            name: A String representing the name of the collection.
            id: An integer value containing the id of the entry. Default None.
            
        Returns:
            A Collection object is returned, where all parameters are set to the given ones.
        """
        if name == None:
            return None
        c = Collection(id, name)
        return c
    
class Audio():
    """An instance of this class represents an entry of the audio table in the media database.
    
    Parameters:
        __id: An integer value containing the id of the entry.
        __media: The corresponding Media object.
        __artist: The corresponding Artist object.
        __comment: The corresponding comment.
        __lyrics: A String containing the corresponding lyrics.
        __tracknumber: An integer containing the corresponding track number.
        __discnumber: An integer containing the corresponding disc number.
        __bitrate: An integer containing the corresponding bit rate. 
        __bpm: An integer containing the corresponding beats per minute.
    """
    def __init__(self, id, media, artist, lyrics, tracknumber, discnumber, bitrate, bpm):
        """The init method."""
        self.__id = id
        #instance of class media
        self.__media = media
        #instance of class artist
        self.__artist = artist
        if lyrics != None:
            lyrics = unicode(lyrics)
        self.__lyrics = lyrics
        self.__tracknumber = tracknumber
        self.__discnumber = discnumber
        self.__bitrate = bitrate
        self.__bpm = bpm
        
    def getId(self):
        """Returns the parameter __id."""
        return self.__id
    
    def setId(self, id):
        """Sets the parameter __id."""
        self.__id = id
    
    def getMedia(self):
        """Returns the parameter __media."""
        return self.__media
    
    def setMedia(self, media):
        """Sets the parameter __media."""
        self.__media = media
    
    def getArtist(self):
        """Returns the parameter __artist."""
        return self.__artist
    
    def setArtist(self, artist):
        """Sets the parameter __artist."""
        self.__artist = artist
    
    def getComment(self):
        """Returns the parameter __comment."""
        return self.__comment
    
    def getLyrics(self):
        """Returns the parameter __lyrics."""
        return self.__lyrics
    
    def getTracknumber(self):
        """Returns the parameter __tracknumber."""
        return self.__tracknumber
    
    def getDiscnumber(self):
        """Returns the parameter __discnumber."""
        return self.__discnumber
    
    def getBitrate(self):
        """Returns the parameter __bitrate."""
        return self.__bitrate
    
    def getBPM(self):
        """Returns the parameter _bpm."""
        return self.__bpm
    
    def getRatingForUsername(self, username):
        """Returns the rating for a specific user
        
        Args:
            username: The user name for which the rating should be returned.
        
        Returns:
            The rating for the given user is returned, or None if there exists no such rating.
        """
        ratings = self.getMedia().getRatings()
        if ratings != None:
            for rating in ratings:
                if rating.getUsername() == username:
                    return rating
        return None
    
    #ids are only relevant if the data comes from the media database (player db ids are not relevant)
    @classmethod
    def createAudioFromAmarok(cls, title, comment, tracknumber, discnumber, bitrate, length, filesize, bpm, artistName, albumName, genreName, year, composer, lyrics, score, rating, playcount, trackId, artistId=None, albumId=None, genreId=None):
        """Class method to create an Audio object with the given parameters.
        
        Args:
            title: A String containing the name of the Media object.
            comment: A String containing the corresponding comment.
            tracknumber: An integer containing the corresponding track number.
            discnumber: An integer containing the corresponding disc number.
            bitrate: An integer containing the corresponding bit rate.
            length: An integer value containing the length of the media.
            filesize: An integer value containing the size of the file where the media is stored.
            bpm: An integer containing the corresponding beats per minute.
            artistName: A String containing the name of the corresponding artist.
            albumName: A String containing the name of the corresponding album.
            genreName: A String containing the name of the corresponding genre.
            year: A Integer containing the year when the Media object was created.
            composer: A String containing the name of the composer.
            lyrics: A String containing the corresponding lyrics.
            score: A float value representing the corresponding score.
            rating: An integer value representing the corresponding score.
            playcount: An integer value representing the corresponding score.
            trackId: An integer value containing the corresponding id.
            artistId: An integer value containing the corresponding artist id or None. Default None.
            albumId: An integer value containing the corresponding album id or None. Default None.
            genreId: An integer value containing the corresponding genre id or None. Default None.
            
        Returns:
            An Audio object is returned, where all parameters are set to the given ones.
        """
        collection = Collection.createCollection(albumName, albumId)
        genre = Genre.createGenre(genreName, genreId)
        artist = Artist.createArtist(artistName, artistId)
        rating = Rating.createRating(score, rating, playcount, comment)
        ratings = []
        ratings.append(rating)
        media = Media.createMedia(title, year, composer, collection, genre, length, filesize, ratings)
        audio = Audio(trackId, media, artist, lyrics, tracknumber, discnumber, bitrate, bpm)
        return audio
    
    @classmethod
    def createAudioFromMediaDb(cls, audioId, lyrics, tracknumber, discnumber, bitrate, bpm, mediaId, mediaType, title, year, composer, length, filetype, filesize, artistId, artistName, genreId, genreName, collectionId, collectionName):
        """Class method to create an Audio object with the given parameters.
        
        Args:
            audioId: An integer value containing the id of the corresponding audio.
            lyrics: A String containing the corresponding lyrics.
            tracknumber: An integer containing the corresponding track number.
            discnumber: An integer containing the corresponding disc number.
            bitrate: An integer containing the corresponding bit rate.
            bpm: An integer containing the corresponding beats per minute.
            mediaId: An integer value containing the id of the corresponding audio.
            mediaType: A String representing the type of the entry, either AUDIO or VIDEO.
            title: A String containing the name of the Media object.
            year: A Integer containing the year when the Media object was created.
            composer: A String containing the name of the composer.
            length: An integer value containing the length of the media.
            filetype: A String containing the type of file.
            filesize: An integer value containing the size of the file where the media is stored.
            artistId: An integer value containing the corresponding artist id.
            artistName: A String containing the name of the corresponding artist.
            genreId: An integer value containing the corresponding genre id.
            genreName: A String containing the name of the corresponding genre.
            collectionId: An integer value containing the corresponding collection id.
            collection Name: A String containing the name of the corresponding collection.
            
        Returns:
            An Audio object is returned, where all parameters are set to the given ones.
        """
        collection = Collection.createCollection(collectionName, collectionId)
        genre = Genre.createGenre(genreName, genreId)
        artist = Artist.createArtist(artistName, artistId)
        media = Media.createMedia(title, year, composer, collection, genre, length, filesize, None, MediaType.AUDIO, mediaId)
        audio = Audio(audioId, media, artist, lyrics, tracknumber, discnumber, bitrate, bpm)
        #Logger.info("  - audio: " + media.getTitle() + "  -  " + artist.getName() + "  -  " + collection.getName())
        return audio

class Artist():
    """An instance of this class represents an entry of the artist table in the media database.
    
    Parameters:
        __id: An integer value containing the id of the entry.
        __name: A String containing the artist's name.
    """
    def __init__(self, id, name):
        """The init method."""
        self.__id = id
        if name != None:
            name = unicode(name)
        self.__name = name
        
    def getId(self):
        """Returns the parameter __id."""
        return self.__id
    
    def setId(self, id):
        """Sets the parameter __id."""
        self.__id = id
    
    def getName(self):
        """Returns the parameter __name."""
        return self.__name
    
    @classmethod
    def createArtist(cls, name, id=None):
        """Class method to create an Artist object with the given parameters.
        
        Args:
            name: A String containing the artist's name.
            id: An integer value containing the id of the entry. Default None.
            
        Returns:
            An Artist object is returned, where all parameters are set to the given ones.
        """
        a = Artist(id, name)
        return a
    
class Rating():
    """An instance of this class represents an entry of the rating table in the media database.
    
    Parameters:
        __id: An integer value containing the id of the entry.
        __mediaId: An integer value containing the id of the corresponding media.
        __username: A String containing the user which should be referenced with the rating.
        __score: A float value representing the corresponding score.
        __rating: An integer value representing the corresponding score.
        __playcount: An integer value representing the corresponding score.
        __comment: A String containing the corresponding comment.
    """
    def __init__(self, id, mediaId, username, score, rating, playcount, comment):
        """The init method."""
        self.__id = id
        self.__mediaId = mediaId
        if comment != None:
            comment = unicode(comment)
        self.__comment = comment
        if username != None:
            username = unicode(username)
        else:
            usersettings = XMLController.readAllSettings().getCurrentUserSettings()
            username = usersettings.getUsername()
        self.__username = username
        self.__score = score
        if self.__score == None:
            self.__score = 0
        self.__rating = rating
        if self.__rating == None:
            self.__rating = 0
        self.__playcount = playcount
        if self.__playcount == None:
            self.__playcount = 0
        
    def getId(self):
        """Returns the parameter __id."""
        return self.__id
    
    def setId(self, id):
        """Sets the parameter __id."""
        self.__id = id
    
    def getMediaId(self):
        """Returns the parameter __MediaId."""
        return self.__mediaId
    
    def getUsername(self):
        """Returns the parameter __username."""
        return self.__username
    
    def setUsername(self, username):
        """Sets the parameter __username."""
        if username != None:
            username = unicode(username)
        self.__username = username
    
    def getScore(self):
        """Returns the parameter __score."""
        return self.__score
    
    def getRating(self):
        """Returns the parameter __rating."""
        return self.__rating
    
    def getPlaycount(self):
        """Returns the parameter __playcount."""
        return self.__playcount
    
    def getComment(self):
        """Returns the parameter __comment."""
        return self.__comment
    
    @classmethod
    def createRating(cls, score, rating, playcount, comment, id=None, username=None, mediaId=None):
        """Class method to create a Rating object with the given parameters.
        
        Args:
            score: A float value representing the corresponding score.
            rating: An integer value representing the corresponding score.
            playcount: An integer value representing the corresponding score.
            comment: A String containing the corresponding comment.
            id: An integer value containing the id of the entry. Default None.
            username: A String containing the user which should be referenced with the rating. Default None.
            mediaId: An integer value containing the id of the corresponding media. Default None.
            
        Returns:
            A Rating object is returned, where all parameters are set to the given ones.
        """
        r = Rating(id, mediaId, username, score, rating, playcount, comment)
        return r
    
class GenreType():
    """An instance of this class represents an entry of the genre table in the media database.
    
    Parameters:
        __id: An integer value containing the id of the entry.
        __name: A String containing the name of the genre.
    """
    def __init__(self, id, name):
        """The init method."""
        self.__id = id
        if name != None:
            name = unicode(name)
        self.__name = name
        
    def getId(self):
        """Returns the parameter __id."""
        return self.__id
    
    def getName(self):
        """Returns the parameter __name."""
        return self.__name

